package day37.edu;

import org.junit.Test;

import java.util.*;

// Created: 07/10/2025, ChangJiang Ru
public class CollectionMapTest {
    @Test
    public void test1()
    {
        ArrayList list = new ArrayList();

        list.add(12);
        list.add(23);
        list.add(67);
        list.add(32);
        list.add(98);
        list.add(65);

        list.add("AA"); // String will have the ClassCastException in 26 line

        Iterator iterator = list.iterator();
        while(iterator.hasNext())
        {
            Integer i = (Integer)iterator.next();
            int score = i;

            System.out.println(score);
        }

    }

    @Test
    public void test2()
    {
        ArrayList<Integer> arrayList = new ArrayList<Integer>();

        arrayList.add(11);
        arrayList.add(23);
        arrayList.add(43);

        Iterator<Integer> iterator = arrayList.iterator();
        while(iterator.hasNext())
        {
            Integer next = iterator.next();
            System.out.println(next);
        }
    }
    
    @Test
    public void test3()
    {
//        HashMap<String,Integer> map = new HashMap<String,Integer>();

        HashMap<String,Integer> map = new HashMap<>();

        map.put("Tom", 12);
        map.put("Jerry", 34);
        map.put("Rose", 32);

        // Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        // Iterator<Map.Entry<String,Integer>> iterator = entrySet.iterator();
        var entrySet = map.entrySet();
        var iterator = entrySet.iterator();

        while(iterator.hasNext())
        {
            Map.Entry<String,Integer> entry = iterator.next();
            String key = entry.getKey();
            Integer value = entry.getValue();

            System.out.println(key + " : " + value);
        }
    }
}
